﻿using System;
using System.Threading;

namespace Se.Thread
{
    public static class SpinLockEx
    {
        public static void Enter(ref SpinLock spinLock)
        {
            bool lockTaken = false;
            spinLock.Enter(ref lockTaken);
        }

        public static void Exit(ref SpinLock spinLock)
        {
            spinLock.Exit(false);
        }

        public static void Exit(ref SpinLock spinLock, bool useMemoryBarrier = false)
        {
            spinLock.Exit(useMemoryBarrier);
        }

        public static bool TryEnter(ref SpinLock spinLock)
        {
            bool lockTaken = false;
            spinLock.Enter(ref lockTaken);
            return lockTaken;
        }

        public static bool TryEnter(ref SpinLock spinLock, TimeSpan timeout)
        {
            bool lockTaken = false;
            spinLock.TryEnter(timeout, ref lockTaken);
            return lockTaken;
        }
    }
}
